#include "startMovieResMessage.h"
#include "operatorResponse.h"
#include "jsonUtils.h"


StartMovieResMessage::StartMovieResMessage(MtpProtocol* packet) : MtpMessage(packet), id(0)
{
}

StartMovieResMessage::StartMovieResMessage(const int64_t& id, MtpMessage* src) : MtpMessage(new MtpProtocol(L"startMovieRes", (MtpProtocol*)src->getPacket())),id(id)
{
}

void StartMovieResMessage::decodeBody()
{
	MtpMessage::decodeBody();
	if (!jsonContent.empty()) {
		OperatorResponse res;
		JsonDoc& doc = res.jsonDeserialize(jsonContent);
		const JsonValue::ConstMemberIterator& it = doc.FindMember(L"data");
		if (it != doc.MemberEnd() && it->value.IsObject()) {
			JsonUtils::loadLong(it->value, L"id", id);
		}
	}
}

void StartMovieResMessage::encodeBody()
{
	OperatorResponse res(true);
	JsonDoc& doc = res.jsonSerialize();
	JsonValue v(rapidjson::kObjectType);
	v.AddMember(L"id", id, doc.GetAllocator());
	doc.AddMember(L"data", v, doc.GetAllocator());
	jsonContent = JsonUtils::jsonStr(doc);
	MtpMessage::encodeBody();
}

const int64_t& StartMovieResMessage::getId() const
{
	return id;
}
